package com.review.dp;

public class LC_152 {
    public int maxProduct(int[] nums) {

        int min = 1;
        int max = 1;
        int res = Integer.MIN_VALUE;

        for (int num : nums) {
            if (num < 0) {
                int tmp = min;
                min = max;
                max = tmp;
            }
            max = Math.max(max * num, num);
            min = Math.min(min * num, num);

            res = Math.max(max, res);
        }
        return res;
    }

    public static void main(String[] args) {
        LC_152 lc_152 = new LC_152();
        System.out.println(lc_152.maxProduct(new int[]{2, 3, -2, 4}));
    }
}
